<template>
	<section>
		<div>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;background-color:#fff">
			  <el-form :inline="true" :model="filters">
			     <el-form-item label="选择创建时间范围:">
                            <el-date-picker
						      v-model="valueDate"
						      type="datetimerange"
						      range-separator="~"
						      start-placeholder="开始日期"
						      end-placeholder="结束日期">
			     </el-date-picker>
                </el-form-item>
				<el-form-item  label="关键字:">
					<el-input v-model="filters.KeyWord" style = "width:300px;" placeholder="根据联系人姓名和申请机构名搜索"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button  v-on:click="getUsers">搜索</el-button>
				</el-form-item>
				<el-form-item>
					<el-button @click="getAllUser">全部</el-button>
				</el-form-item>
				
			</el-form>
		</el-col>

		<!--列表-->
		<el-table :style = "conheight" :data="tableData" @row-click="openDetails"  highlight-current-row v-loading="listLoading" @selection-change="selsChange" style="width: 100%;padding:15px;text-align:center;overflow-y:auto">
			<!-- <el-table-column type="selection" width="55">
			</el-table-column> -->
			<el-table-column prop="RowNum" label="序号" width="80" >
			</el-table-column>
			<el-table-column prop="LinkName" label="联系人" width="100">
			</el-table-column>
			<el-table-column prop="phone" label="手机" width="140">
			</el-table-column>
            <el-table-column prop="email" label="邮箱" width="140">
			</el-table-column>
			<el-table-column prop="applyOrgan" label="申请机构" width="140">
			</el-table-column>
			<el-table-column prop="position" label="联系人职位" width="140">
			</el-table-column>
			<el-table-column prop="website" label="网站" width="140">
			</el-table-column>
			<el-table-column prop="cooperation" label="合作意向" min-width="180" >
			</el-table-column>
			<el-table-column prop="detailMsg" label="详细信息" min-width="300">
			</el-table-column>
			<el-table-column prop="applyTime" label="申请时间" min-width="180">
			</el-table-column>
			<el-table-column label="操作" width="140">
				<template slot-scope="scope">
					<el-button  size="small"  @click.stop="handleDel(scope.$index, scope.row)" class = "delBtnSty">删除</el-button>
				</template>
			</el-table-column>
		</el-table>
       
		<!--工具条-->
		<el-col :span="24" class="toolbar">
			<el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :page-size="ps" :total="total" style="text-align:center;">
			</el-pagination>
		</el-col>
		</div>
	</section>
</template>

<script>
     import axios from 'axios';
     import { isPhone,isEmail,isPassword } from "@/common/js/validate"
	export default {
		data() {
			return {
		      valueDate:['2019-08-08','2019-08-08'],
			  conheight:{
                height:''
               },
               conheightEdit:{
                height:''
               },
				tableData: [{'RowNum':'1','phone':'18698760987','LinkName':'张三','email':'123@qq.com','applyOrgan':'默幼儿晕啊','position':'教师','website':'www.123.com','cooperation':'言语康复','detailMsg':'很想了解产品情况以及费用情况，想做试点单位，主要是用于有效的解决智障问题。','applyTime':'2019/09/09 12:00:00',}],
				filters: {
					KeyWord: '',
					region:'',
					time:''
				},
				users: [],
				total: 0,
				page: 1,
				ps:10,
				listLoading: false,
				sels: [],//列表选中列
			}
		}, 
		  created() {
	     window.addEventListener('resize', this.getHeight);
	        this.getHeight()
	    },
		methods: {
			myStudent(index, row){
				 this.listLoading = true;
				 this.isStudent = true;
				 let Start
                 let End
                 if(this.filters.time[0] == undefined){
                      Start = ''
                 }else{
                 	 Start =  new Date(this.filters.time[0]).format("yyyy-MM-dd hh:mm:ss")
                 }
                  if(this.filters.time[1] == undefined){
                      End = ''
                 }else{
                 	 End =  new Date(this.filters.time[1]).format("yyyy-MM-dd hh:mm:ss")
                 }
				 let obj = {StartDay:Start,EndDay:End,Keyword:this.filters.KeyWord,Pn:this.studentPn,Ps:this.studentPs};
                  axios.post('/api/School/MyStudent?id='+row.AccountID, obj).then((response)=>{
	              	 console.log( response.data.CurPager.ResultList)
	              	  this.tableData = response.data.CurPager.ResultList
	                 this.listLoading = false;
	              }).catch(function (error) {
	                console.log(error);
	              });
			},
			 openDetails (row,event,column) {
			 	console.log(row)
			 	if(column.type !== 'selection'){
                    this.isDetail = true;
			        //具体操作        
			       axios.get('/api/School/TeacherDetail',  {params:{  tid:row.AccountID,}
		              }).then((response)=>{
		              		console.log(response.data);
		                   this.teacherEditMsgForm.id = response.data.Data.Account.id
                          this.teacherEditMsgForm.sex = response.data.Data.Account.Sex
                          this.teacherEditMsgForm.birth = response.data.Data.Teacher.Birthday
                          this.teacherEditMsgForm.office = response.data.Data.Teacher.GraduateSchool
                          this.teacherEditMsgForm.name = response.data.Data.Account.RealName
                          this.teacherEditMsgForm.EducationBackground = response.data.Data.Teacher.EducationBackground
		              }).catch(function (error) {
		                console.log(error);
		              });
			 	}
			 	 
			   },
			  getHeight(){
		          this.conheight.height=window.innerHeight-250+'px';
		          this.conheightEdit.height=window.innerHeight-150+'px';
		       },
			//性别显示转换
			formatSex: function (row, column) {
				return row.Sex == "m" ? '男' : row.Sex == "f" ? '女' : '未知';
			},
			toDate: function (row, column) {
				return row.JoinTime.substr(0,19).replace('T',' ');
			},
			toCreateDate: function (row, column) {
				return row.CreateTime.substr(0,19).replace('T',' ');
			},
			toEndDate: function (row, column) {
				return row.EndDate.substr(0,19).replace('T',' ');
			},
			toSex: function (sex) {
				//return sex == "m" ? '男' : sex == "f" ? '女' : '未知';
			},
			handleCurrentChange(val) {
				this.page = val;
				this.getUsers();
			},
				//显示新增界面
			handleAdd: function () {
				this.addFormVisible = true;
				this.addForm = {
					loginName: '',
					password: '',
					ispassword: '',
					realName: '',
					Sex:'f'
				};
			},
			handleisPassword(){
				let value = this.addForm.password
				let value1 = this.addForm.ispassword
			     if(value != value1){
                    this.isPassWordDiff = true
			     }else{
			     	this.isPassWordDiff = false
			     }
			},
			addSubmit(){
				this.addLoading = true;
				if(this.isloginNameNone == false &&this.isPassWordNone == false &&this.isPasswordError == false &&this.isPassWordDiff == false &&this.isrealNameNone == false){
                 axios.post('/api/School/EditTeacher',  {
	                   id:0,
	                   LoginName:this.addForm.loginName,
	                   Password:this.addForm.password,
	                   Sex:this.addForm.Sex,
	                   RealName:this.addForm.realName
	              }).then((response)=>{
	              	    this.addLoading = false;
	              	 	this.addFormVisible = false;
	              	 	console.log(response.data.Msg);
	              	 	this.getUsers();
	              }).catch(function (error) {
	                console.log(error);
	              });
				}
			},
				//删除
			handleStudentDel: function (index, row) {
				this.$confirm('确认删除吗？', '提示', {
					type: 'warning'
				}).then(() => {
					 axios.get('/api/School/DelStudent',  {params:{  sid:row.AccountID,}
		              }).then((response)=>{
		              	// console.log( response.data)
		              	this.getUsers()
		              }).catch(function (error) {
		                console.log(error);
		              });
				}).catch(() => {

				});
			},
			//获取全部用户
			getAllUser(){
				this.filters.time = '';
                this.filters.KeyWord = '';
                this.getUsers();
			},
			//获取用户列表
			getUsers() {
				 this.listLoading = true;
				 let Start
                 let End
                 if(this.filters.time[0] == undefined){
                      Start = ''
                 }else{
                 	 Start =  new Date(this.filters.time[0]).format("yyyy-MM-dd hh:mm:ss")
                 }
                  if(this.filters.time[1] == undefined){
                      End = ''
                 }else{
                 	 End =  new Date(this.filters.time[1]).format("yyyy-MM-dd hh:mm:ss")
                 }
				let obj = {StartDay:Start,EndDay:End,Keyword:this.filters.KeyWord,CurPager:null};
	             axios.post('/api/School/Teacher?pn='+this.page+'&ps='+this.ps,obj).then((response)=>{
	              	// console.log( response.data)
	                 this.page = response.data.CurPager.CurPage
	                 this.PageSize = response.data.CurPager.PageSize
	                 this.total = response.data.CurPager.TotalPages
	                 this.tableData = response.data.CurPager.ResultList
	                 this.listLoading = false;
	              }).catch(function (error) {
	                console.log(error);
	              });
			},
			//删除
			handleDel: function (index, row) {
				this.$confirm('确认删除选中记录吗？', '提示', {
					type: 'warning'
				}).then(() => {
						this.listLoading = true;
					 axios.get('/api/School/DelTeacher',  {params:{  tid:row.AccountID,}
		              }).then((response)=>{
		              	this.listLoading = false;
		              	// console.log( response.data)
		              	console.log(response.data.Msg)
		              	this.getUsers();
		              }).catch(function (error) {
		                console.log(error);
		              });
				}).catch(() => {

				});
				
			},
			selsChange: function (sels) {
				this.sels = sels;
			},
		},
		mounted() {
			   // this.getUsers();
				//this.listLoading = true;
			  // axios.get('/api/School/GetTeacherList')
     //          .then((response)=>{
     //             this.total = response.data.length;
     //          })
     //          .catch(function (error) {
     //            console.log(error);
     //          });
            
		}
	}

</script>

<style>
.el-table__body, .el-table__header {
    width: auto!important;
    text-align: center;
}
.bottomRight{
	padding-left:50px;
}
.num{
	width:150px;
}
.rightBox{
	height:40px;
	line-height:40px;
	border:1px solid #ccc;
	min-width:100px;
	border-radius:5px;
	padding:0 20px;
}
.errorBox{
	color:red;
}
div.cell{
	text-align:center;
}
.el-submenu__title {
	color:#fff
}
.titleBox{
	height:50px;
	line-height:50px;
}
.el-dialog__header {
    padding:15px 20px;
  
    background-color: #20a0ff;
}
.el-dialog__title{
	  color: #fff;
}
tr{
	cursor:pointer;
}
.btnSty,.delBtnSty{
	color:#50D285;
	border:none;
	font-weight:bold;
	background:rgba(0,0,0,0);
	margin-left:0px !important;
}
.btnSty{
	border-right:2px solid #f1f1f1;
	border-radius:0;
}
.btnSty:hover,.delBtnSty:hover{
		background:rgba(0,0,0,0)
}
.delBtnSty{
	color:#AFAFAF
}
</style>